<?php


namespace app\lunwen\controller;


use app\lunwen\model\DepartmentUploadFileModel;
use app\lunwen\model\EducationalCheckBestModel;
use app\lunwen\model\ExternalMarkGradeModel;
use cmf\controller\HomeBaseController;

class TeacherSetGradeController extends HomeBaseController
{
    public function index(){
        $file = new EducationalCheckBestModel();
        $data = $file->all();
        $this->assign('title',$data);
        return $this->fetch(":teacherSetGrade");
    }

    public function downButton(){

        $data = "D:\phpstudy_pro\\thinkcmf\ThinkCMF\public\static\\educationalFile\\{$_GET["file_name"]}";
        echo $filename = $_GET["file_name"];
        return \download($data,$_GET["file_name"],false);

    }

    public function setGrade(){
        return $this->fetch(":teacherMarkGrade");
    }

    //外部人员评分页面
    public function markPage(){
        return $this->fetch(":externalMarkGrade");
    }

    //外部人员评分
    public function mark(){
        $fileNameString = $_POST["file_name"];
        $stuId = strstr($fileNameString,'_',true);

        $data = strstr($fileNameString,'_');
        $beformStuName = strstr($data,'.',true);
        $stuname = substr("$beformStuName", 1, strlen($beformStuName));

        //文件名 分数   老师名 学生名 学生id 插入mark_grade表
        $external = new ExternalMarkGradeModel();
        $external->file_name = $_POST["file_name"];
        $external->external_grader = $_POST["grade"];
        $external->external_name = session("teacher_name");
        $external->student_id =$stuId;
        $external->student_name =$stuname;
        $external->save();

        return json([
            'msg'=>'评分成功',
            'code'=>1,
        ]);
    }

    public function checkGrade(){

        $grade = new ExternalMarkGradeModel();
        $data = $grade ->whereTime('create_time','>',session('beforeYear'))
            ->whereTime('create_time','<',session('afterYear'))
            ->all();
        $this->assign('title',$data);
        return $this->fetch(":externalCheckGrade");
    }

    public function delButton(){
        $del = new ExternalMarkGradeModel();
        $del->where('student_id',$_GET["stu_id"])
            ->delete();

        $grade = new ExternalMarkGradeModel();
        $data = $grade
            ->whereTime('create_time','>',session('beforeYear'))
            ->whereTime('create_time','<',session('afterYear'))
            ->all();
        $this->assign('title',$data);
        return $this->fetch(":externalCheckGrade");
    }


}